package l1j.opqlo.移民;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.opqlo.NewSystem.A_ColorMessage;
import l1j.opqlo.NewSystem.各項記錄輸出;
import l1j.opqlo.NewSystem.ItemLevelUp.ItemLevelUpTable;
import l1j.opqlo.Server.QuitGame;
import l1j.opqlo.Server.L1World.L1World;
import l1j.server.DatabaseFactory;
import l1j.server.DatabaseFactoryLogin;
import l1j.server.Thread.GeneralThreadPool;
import l1j.server.server.IdFactory;
import l1j.server.server.datatables.CharObjidTable;
import l1j.server.server.datatables.CharacterTable;
import l1j.server.server.datatables.ItemTable;
import l1j.server.server.datatables.lock.CharItemsReading;
import l1j.server.server.datatables.lock.CharSkillReading;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.templates.L1Item;
import l1j.server.server.utils.Random;
import l1j.server.server.utils.SQLUtil;

public class checkThread  extends TimerTask {

	private final static Logger _log = Logger.getLogger(checkThread.class.getName());

	private ScheduledFuture<?> _timer;
	private final ArrayList<Temp>_list = new ArrayList<Temp>();

	public void start(){
		_timer = GeneralThreadPool.getInstance().scheduleAtFixedRate(this, 10000, 10000);
	}

	@Override
	public void run() {
		try{
			load();
			if(!_list.isEmpty()){
				load2();
			}
		} catch (final Exception e) {
			_log.log(Level.SEVERE ,e.getLocalizedMessage(), e);
			System.out.println("PC 移民處理時間軸異常重啟");
			GeneralThreadPool.getInstance().cancel(_timer, false);
			checkThread t = new checkThread();
			t.start();
		}
	}

	private void load(){
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = DatabaseFactory.get().getConnection();
			pstm = con.prepareStatement("SELECT * FROM `z_opqlo_migrate`");
			rs = pstm.executeQuery();
			while (rs.next()) {
				Thread.sleep(3);
				Temp temp = new Temp();
				temp._account = rs.getString("Account_name");
				temp._name1 = rs.getString("name_1");
				temp._name2 = rs.getString("name_2");
				temp._objid1 = rs.getInt("objid_1");
				temp._objid2 = rs.getInt("objid_2");
				temp._newAccount = rs.getString("newAccount");

//				L1Account account = AccountReading.get().getAccount(temp._newAccount);
//				if (account == null) {
					L1World.getInstance().broadcastPacketToAll(new A_ColorMessage(A_ColorMessage.紫色 , "【移民】有新的移民加入了伺服器!!!"));
//					account = AccountReading.get().create(temp._newAccount, temp._pass, "127.0.0.1", "127.0.0.1" , null);
//					banAccount(temp._newAccount , 1);//處理完畢前暫時鎖定帳號。
					_list.add(temp);
//				}else{
//					System.out.println(temp._newAccount+" 帳號重複，取消動作。");
//				}
			}
		} catch (final SQLException e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);

		} catch (final Exception e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}
	//CharSkillReading

	private void load2(){
		if(_list.isEmpty()){
			return;
		}
		for(final Temp temp : _list){
			L1PcInstance pc = loadCharacter(temp._objid1 ,temp._newAccount);
			if(pc != null){
				final StringBuilder msg = new StringBuilder();
				msg.append("帳號: ").append(temp._account).append(" / ").append(temp._newAccount).append("	名稱: ").append(temp._name1).append(" ID:[ ").append(temp._objid1).append("	/	").append(pc.getId()).append(" ]\r\n");
				msg.append("-------------------【 背	包 】--------------------").append("\r\n\r\n");
				// 建立人物資料
				try {
					pc.setAccountName(temp._newAccount);
					CharacterTable.getInstance().storeNewCharacter(pc);

					// 紀錄人物初始化資料
					//			CharacterTable.saveNewCharStatus(pc);
					// 加入建立PC OBJID資料
					CharObjidTable.get().addChar(pc.getId(), pc.getName());

					loadSkill(temp._objid1 , pc.getId());
					loadQuest(pc , temp._objid1);
					loadInvItems(temp._objid1 , pc.getId() , msg);
					loadDwfItems(pc ,temp._account, msg);
					QuitGame.quitGame(pc);
					各項記錄輸出.LogSave(33, msg.toString());
					msg.delete(0, msg.length());

					if(temp._objid2 >0){
						pc = loadCharacter(temp._objid2 ,temp._newAccount);

						msg.append("帳號: ").append(temp._account).append(" / ").append(temp._newAccount).append("	名稱: ").append(temp._name2).append(" ID:[ ").append(temp._objid2).append("	/	").append(pc.getId()).append(" ]\r\n");
						msg.append("-------------------【 背	包 】--------------------").append("\r\n\r\n");

						// 建立人物資料
						CharacterTable.getInstance().storeNewCharacter(pc);
						// 紀錄人物初始化資料
						//				CharacterTable.saveNewCharStatus(pc);
						// 加入建立PC OBJID資料
						CharObjidTable.get().addChar(pc.getId(), pc.getName());

						loadSkill(temp._objid2 , pc.getId());
						loadQuest(pc ,temp._objid2);
						loadInvItems(temp._objid2 , pc.getId() , msg);
						QuitGame.quitGame(pc);
						各項記錄輸出.LogSave(33, msg.toString());
						msg.delete(0, msg.length());
					}
				} catch (Exception e) {
					_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
					System.out.println("load2異常。"+e.getLocalizedMessage());
				}
				banAccount(temp._newAccount , 0);//處理完畢前暫時鎖定帳號。
			}
			deleteValue(temp._account);
		}
		_list.clear();
	}

	private void deleteValue(final String login){
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = DatabaseFactory.get().getConnection();
			pstm = con.prepareStatement("DELETE FROM z_opqlo_migrate WHERE Account_name =?");
			//			pstm = con.prepareStatement("DELETE FROM z_opqlo_migrate");
			pstm.setString(1, login);
			pstm.execute();
		} catch (final SQLException e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
		} finally {
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}



	private void loadSkill(final int objid , final int newid){
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = DatabaseFactoryServer.get().getConnection();
			pstm = con.prepareStatement("SELECT * FROM character_skills WHERE char_obj_id=?");
			pstm.setInt(1, objid);
			rs = pstm.executeQuery();
			while (rs.next()) {
				if(newid != objid){
					CharSkillReading.get().spellMastery(newid, rs.getInt("skill_id"), rs.getString("skill_name"), 0, 0);
				}else{
					CharSkillReading.get().spellMastery(objid, rs.getInt("skill_id"), rs.getString("skill_name"), 0, 0);
				}
			}
		} catch (final SQLException e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}


	private void loadQuest(final L1PcInstance pc , final int objid ){

		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = DatabaseFactoryServer.get().getConnection();
			pstm = con.prepareStatement("SELECT * FROM character_quests WHERE char_id=?");
			pstm.setInt(1, objid);
			rs = pstm.executeQuery();
			while (rs.next()) {
				pc.getQuest().set_step(rs.getInt("quest_id"), rs.getInt("quest_step"));
			}
		} catch (final SQLException e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	private void loadInvItems(final int objid , final int newid, StringBuilder msg){
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = DatabaseFactoryServer.get().getConnection();
			pstm = con.prepareStatement("SELECT * FROM character_items WHERE char_id =?");
			pstm.setInt(1, objid);
			rs = pstm.executeQuery();
			while (rs.next()) {
				L1ItemInstance item;
				final  int char_id;
				if(objid != newid){
					char_id = newid;
				}else{
					char_id = objid;
				}

				final int item_id = rs.getInt("item_id");
				// 檢查該資料所屬是否遺失
				if (CharObjidTable.get().isChar(char_id) != null) {
					final L1Item itemTemplate = ItemTable.getInstance().getTemplate(item_id);
					if (itemTemplate == null) {// 無該物品資料
						continue;
					}

					item = new L1ItemInstance();
					final int id = rs.getInt("id");
					item.setId(IdFactory.getInstance().nextId());
					item.setItem(itemTemplate);
					item.setRemainingTime(rs.getInt("remaining_time")); // opqlo 測試防止計時物品 讀取時消失問題
					item.setCount(rs.getInt("count"));
					item.setEquipped(rs.getInt("Is_equipped") != 0 ? true : false);
					item.setEnchantLevel(rs.getInt("enchantlvl"));
					item.setIdentified(rs.getInt("is_id") != 0 ? true : false);
					item.set_durability(rs.getInt("durability"));
					item.setChargeCount(rs.getInt("charge_count"));
					item.setLastUsed(rs.getTimestamp("last_used"));
					item.setBless(rs.getInt("bless"));
					item.setAttrEnchantKind(rs.getInt("attr_enchant_kind"));
					item.setAttrEnchantLevel(rs.getInt("attr_enchant_level"));
					//TODO 飾品強化卷軸
					item.setFireMr(rs.getInt("firemr"));
					item.setWaterMr(rs.getInt("watermr"));
					item.setEarthMr(rs.getInt("earthmr"));
					item.setWindMr(rs.getInt("windmr"));
					item.setaddSp(rs.getInt("addsp"));
					item.setaddHp(rs.getInt("addhp"));
					item.setaddMp(rs.getInt("addmp"));
					item.setHpr(rs.getInt("hpr"));
					item.setMpr(rs.getInt("mpr"));
					//TODO 飾品強化卷軸
					//TODO 魔法武器卷軸by missu0524
					item.setSkillType(rs.getInt("skilltype"));
					//TODO 魔法武器卷軸by missu0524
					// opqlo道具天數刪除系統
					item.setDeleteDate(rs.getTimestamp("DeleteDate"));
					//opqlo 道具升級系統START
					final int level = rs.getInt("level");
					if(level > 1){
						item.setLevel(level);
						ItemLevelUpTable.getInstance().getLevelStatus(item);
					}
					//opqlo 道具升級系統END
					item.getLvStatus().setItemSpecialDmg(item , rs.getString("屬性增傷") ,0);
					item.getLvStatus().setItemSpecialDmg(item , rs.getString("六屬性加成") ,1);
					item.getLvStatus().setItemSpecialDmg(item, rs.getString("種族增傷"), 2);
					item.setExtraDmg(rs.getInt("破甲"));
					item.setExtraDef(rs.getInt("抵擋"));
					item.setModDmg(rs.getInt("額外攻擊"));
					item.setModHit(rs.getInt("攻擊成功"));
					item.setExpUp(rs.getDouble("經驗"));
					item.setDoubleDmg(rs.getInt("爆擊"));
					item.setBigDmg(rs.getInt("大怪"));
					item.setSmallDmg(rs.getInt("小怪"));
					item.setaddMr(rs.getInt("魔防"));
					item.setStunDice(rs.getInt("暈眩"));
					item.setStoneDice(rs.getInt("石化"));
					item.setSleepDice(rs.getInt("睡眠"));
					item.setFreezeDice(rs.getInt("凍結"));
					item.setSustainDice(rs.getInt("支撐"));
					item.setBlindDice(rs.getInt("暗黑"));
					item.setStunMr(rs.getInt("暈眩抗性"));
					item.setStoneMr(rs.getInt("石化抗性"));
					item.setSleepMr(rs.getInt("睡眠抗性"));
					item.setFreezeMr(rs.getInt("凍結抗性"));
					item.setSustainMr(rs.getInt("支撐抗性"));
					item.setBlindMr(rs.getInt("暗黑抗性"));
					item.addDroprate(rs.getDouble("掉寶率")); //opqlo 掉寶率
					item.getLvStatus().setAttrDef(1, rs.getDouble("地減傷"));
					item.getLvStatus().setAttrDef(2, rs.getDouble("火減傷"));
					item.getLvStatus().setAttrDef(4, rs.getDouble("水減傷"));
					item.getLvStatus().setAttrDef(5, rs.getDouble("光減傷"));
					item.getLvStatus().setAttrDef(6, rs.getDouble("闇減傷"));
					item.getLvStatus().setAttrDef(8, rs.getDouble("風減傷"));
					item.setMagicDmgMod(rs.getInt("魔法增傷"));
					item.getLastStatus().updateAll();
					L1World.getInstance().storeObject(item);
					CharItemsReading.get().storeItem(char_id, item);
					msg.append(item.getViewName()).append("	流水號:[ ").append(id).append("	/	").append(item.getId()).append(" ]\r\n");
				}
			}
			msg.append("-------------------【 倉	庫 】--------------------").append("\r\n\r\n");
		} catch (final SQLException e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);

		} catch (Exception e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	private void loadDwfItems(final L1PcInstance pc, final String Account , StringBuilder msg){
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = DatabaseFactoryServer.get().getConnection();
			pstm = con.prepareStatement("SELECT * FROM character_warehouse WHERE account_name = ?");
			pstm.setString(1, Account);
			rs = pstm.executeQuery();
			while (rs.next()) {
				final L1ItemInstance item = new L1ItemInstance();
				final int id = rs.getInt("id");
				item.setId(IdFactory.getInstance().nextId());
				final int itemid = rs.getInt("item_id");
				final L1Item itemTemplate = ItemTable.getInstance().getTemplate(itemid);
				item.setItem(itemTemplate);
				item.setCount(rs.getInt("count"));
				item.setEquipped(false);
				item.setEnchantLevel(rs.getInt("enchantlvl"));
				item.setIdentified(rs.getInt("is_id") != 0 ? true : false);
				item.set_durability(rs.getInt("durability"));
				item.setChargeCount(rs.getInt("charge_count"));
				item.setRemainingTime(rs.getInt("remaining_time"));
				item.setLastUsed(rs.getTimestamp("last_used"));
				item.setBless(rs.getInt("bless"));
				item.setAttrEnchantKind(rs.getInt("attr_enchant_kind"));
				item.setAttrEnchantLevel(rs.getInt("attr_enchant_level"));
				//TODO 飾品強化卷軸
				item.setFireMr(rs.getInt("firemr"));
				item.setWaterMr(rs.getInt("watermr"));
				item.setEarthMr(rs.getInt("earthmr"));
				item.setWindMr(rs.getInt("windmr"));
				item.setaddSp(rs.getInt("addsp"));
				item.setaddHp(rs.getInt("addhp"));
				item.setaddMp(rs.getInt("addmp"));
				item.setHpr(rs.getInt("hpr"));
				item.setMpr(rs.getInt("mpr"));
				//TODO 飾品強化卷軸
				//TODO 魔法武器卷軸by missu0524
				item.setSkillType(rs.getInt("skilltype"));
				//TODO 魔法武器卷軸by missu0524
				//opqlo 道具升級系統START
				final int level = rs.getInt("level");
				if(level > 1){
					item.setLevel(level);
					ItemLevelUpTable.getInstance().getLevelStatus(item);
				}
				//opqlo 道具升級系統END
				item.getLvStatus().setItemSpecialDmg(item , rs.getString("屬性增傷") ,0);
				item.getLvStatus().setItemSpecialDmg(item , rs.getString("六屬性加成") ,1);
				item.getLvStatus().setItemSpecialDmg(item, rs.getString("種族增傷"), 2);
				item.setExtraDmg(rs.getInt("破甲"));
				item.setExtraDef(rs.getInt("抵擋"));
				item.setModDmg(rs.getInt("額外攻擊"));
				item.setModHit(rs.getInt("攻擊成功"));
				item.setExpUp(rs.getDouble("經驗"));
				item.setDoubleDmg(rs.getInt("爆擊"));
				item.setBigDmg(rs.getInt("大怪"));
				item.setSmallDmg(rs.getInt("小怪"));
				item.setaddMr(rs.getInt("魔防"));
				item.setStunDice(rs.getInt("暈眩"));
				item.setStoneDice(rs.getInt("石化"));
				item.setSleepDice(rs.getInt("睡眠"));
				item.setFreezeDice(rs.getInt("凍結"));
				item.setSustainDice(rs.getInt("支撐"));
				item.setBlindDice(rs.getInt("暗黑"));
				item.setStunMr(rs.getInt("暈眩抗性"));
				item.setStoneMr(rs.getInt("石化抗性"));
				item.setSleepMr(rs.getInt("睡眠抗性"));
				item.setFreezeMr(rs.getInt("凍結抗性"));
				item.setSustainMr(rs.getInt("支撐抗性"));
				item.setBlindMr(rs.getInt("暗黑抗性"));
				item.addDroprate(rs.getDouble("掉寶率")); //opqlo 掉寶率
				item.getLvStatus().setAttrDef(1, rs.getDouble("地減傷"));
				item.getLvStatus().setAttrDef(2, rs.getDouble("火減傷"));
				item.getLvStatus().setAttrDef(4, rs.getDouble("水減傷"));
				item.getLvStatus().setAttrDef(5, rs.getDouble("光減傷"));
				item.getLvStatus().setAttrDef(6, rs.getDouble("闇減傷"));
				item.getLvStatus().setAttrDef(8, rs.getDouble("風減傷"));
				L1World.getInstance().storeObject(item);
				pc.getDwarfInventory().insertItem(item);
				msg.append(item.getViewName()).append("	流水號:[ ").append(id).append("	/	").append(item.getId()).append(" ]\r\n");
			}
			msg.append("---------------------------------------").append("\r\n\r\n");
//			deleteItem(Account);
		} catch (final SQLException e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
			System.out.println("SQLException: "+e.getLocalizedMessage());
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	private L1PcInstance loadCharacter(final int objid , final String account) {
		L1PcInstance pc = null;
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = DatabaseFactoryServer.get().getConnection();
			pstm = con.prepareStatement("SELECT * FROM characters WHERE objid =?");
			pstm.setInt(1, objid);
			rs = pstm.executeQuery();
			if (!rs.next()) {
				/*
				 * SELECTが結果を返さなかった。
				 */
				return null;
			}
			pc = new L1PcInstance();
			pc.setAccountName(account);
			if(CharObjidTable.get().isChar(objid) !=null){ //已有此 OBJID
				pc.setId(IdFactory.getInstance().nextId());
			}else{
				pc.setId(objid);
			}
			String name = String.valueOf((Random.nextInt(99999)+999));
			while(CharObjidTable.get().charObjid(name) >0){
				name = String.valueOf((Random.nextInt(99999)+999));
			}
			pc.setName(name);
			//TODO 角色誕生by99團隊
			pc.setBirthday(rs.getTimestamp("birthday"));
			//TODO 角色誕生by99團隊
			pc.setHighLevel(rs.getInt("HighLevel"));
			pc.setExp(rs.getInt("Exp"));
			pc.addBaseMaxHp(rs.getInt("MaxHp"));
			pc.setCurrentHpDirect(rs.getInt("CurHp"));
			pc.setDead(false);
			pc.setStatus(0);
			pc.addBaseMaxMp(rs.getShort("MaxMp"));
			pc.setCurrentMpDirect(rs.getShort("CurMp"));
			//opqlo 七屬性破127
			pc.addBaseStr(rs.getShort("Str"));
			pc.addBaseCon(rs.getShort("Con"));
			pc.addBaseDex(rs.getShort("Dex"));
			pc.addBaseCha(rs.getShort("Cha"));
			pc.addBaseInt(rs.getShort("Intel"));
			pc.addBaseWis(rs.getShort("Wis"));
			//opqlo 七屬性破127
			int status = rs.getInt("Status");
			pc.setCurrentWeapon(status);
			int classId = rs.getInt("Class");
			pc.setClassId(classId);
			pc.setTempCharGfx(classId);
			pc.setGfxId(classId);
			pc.set_sex(rs.getInt("Sex"));
			pc.setType(rs.getInt("Type"));
			pc.setHeading(0);
			pc.setX(rs.getInt("locX"));
			pc.setY(rs.getInt("locY"));
			pc.setMap(rs.getShort("MapID"));
			pc.set_food(rs.getInt("Food"));
			pc.setLawful(rs.getInt("Lawful"));
			pc.setTitle(rs.getString("Title"));
			pc.setClanid(0);
			pc.setClanname("");
			pc.setClanRank(0);
			pc.setBonusStats(rs.getInt("BonusStatus"));
			pc.setElixirStats(rs.getInt("ElixirStatus"));
			pc.setElfAttr(rs.getInt("ElfAttr"));
			pc.set_PKcount(0);
			pc.setPkCountForElf(0);
			pc.setExpRes(rs.getInt("ExpRes"));
			pc.setPartnerId(0);
			pc.setAccessLevel((short) 0);
			pc.setOnlineStatus(1);
			pc.setHomeTownId(rs.getInt("HomeTownID"));
			pc.setContribution(rs.getInt("Contribution"));
			pc.setHellTime(0);
			pc.setBanned(rs.getBoolean("Banned"));
			pc.setKarma(0);
			pc.set_metempsychosis(rs.getInt("metempsychosis"));//TODO 記錄轉生次數
			pc.setLastPk(null);
			pc.setLastPkForElf(null);
			pc.setDeleteTime(null);
			pc.setOriginalStr(rs.getInt("OriginalStr"));
			pc.setOriginalCon(rs.getInt("OriginalCon"));
			pc.setOriginalDex(rs.getInt("OriginalDex"));
			pc.setOriginalCha(rs.getInt("OriginalCha"));
			pc.setOriginalInt(rs.getInt("OriginalInt"));
			pc.setOriginalWis(rs.getInt("OriginalWis"));
			pc.setLastActive(null);// TODO 殷海薩的祝福
			pc.setAinZone(0);// TODO 殷海薩的祝福
			pc.setAinPoint(0);// TODO 殷海薩的祝福
			pc.refresh();
			pc.setMoveSpeed(0);
			pc.setBraveSpeed(0);
			pc.setGmInvis(false);
			pc.getExpRate= rs.getDouble("ExpRate");//opqlo 經驗加倍
//			pc.setLogPartyId(0); //opqlo 斷線重登會自動加入原本隊伍
			pc.inQuestGame = false;
			pc.login刮刮樂(null);
			pc.setChangeName(1);
			_log.finest("restored char data: ");
		} catch (SQLException e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
		} catch (final Exception e) {
			_log.log(Level.SEVERE,e.getLocalizedMessage(), e);
		} finally {
			SQLUtil.close(rs , pstm , con);
		}
		return pc;
	}
	private void banAccount(final String login , final int ban){
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = DatabaseFactoryLogin.get().getConnection();
			final String sqlstr = "UPDATE `accounts` SET `banned`=? WHERE `login`=?";
			pstm = con.prepareStatement(sqlstr);
			pstm.setInt(1, ban);

			pstm.setString(2, login);
			pstm.execute();

		} catch (final Exception e) {
			_log.log(Level.SEVERE ,e.getLocalizedMessage(), e);

		} finally {
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}
}
class Temp{
	public int _objid1 , _objid2;
	public String _name1 , _name2;
	public String _account;
	public String _newAccount;
}
